package ordered_table

import (
	"fmt"
	"strconv"
)

func PrintAll(head *SBTreeNode){
	fmt.Println("size balance tree print")
	PrintInOrder(head, 0, "H", 20)
}

func PrintInOrder(head *SBTreeNode, level int, direct string, formatLen int){
	if head == nil {return}
	PrintInOrder(head.Right, level+1, "V", formatLen)
	keyStr := strconv.Itoa(head.Key.GetValue()) + ":" + strconv.Itoa(head.Size)+ ":"+ fmt.Sprintf("%s", head.Value)
	fmt.Println(GetSpace(level*formatLen) + direct + keyStr  + GetSpace(formatLen-len(keyStr)) + direct)
	PrintInOrder(head.Left, level+1, "^", formatLen)
}

func GetSpace(num int) string {
	ans := ""
	for i:=1; i<=num; i++ {
		ans += " "
	}
	return ans
}

func PrintAll2(head *Node){
	fmt.Println("-------------------- size balance tree print  -------------------------------")
	PrintInOrder2(head, 0, "H", 20)
}

func PrintInOrder2(head *Node, level int, direct string, formatLen int){
	if head == nil {return}
	PrintInOrder2(head.Right, level+1, "V", formatLen)
	keyStr := strconv.Itoa(head.Key) + ":" + strconv.Itoa(head.Size)+ ":"+ strconv.Itoa(head.All)
	fmt.Println(GetSpace(level*formatLen) + direct + keyStr  + GetSpace(formatLen-len(keyStr)) + direct)
	PrintInOrder2(head.Left, level+1, "^", formatLen)
}